﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using baseSet.importExport;
using dhDataAcess.baseBLL;
using dhSystemBLL.orderData;

namespace dhsystem.produceForm.Stock
{
    public partial class FrmmaterialStockListDetail : Form
    {
        MaterialTypeBLL materialType = new MaterialTypeBLL();
        supplierListBLL supplier = new supplierListBLL();
        public FrmmaterialStockListDetail()
        {
            InitializeComponent();
        }

        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.materialListstockDetail, dGridmaterialStockList, "原材料库存报表");
            frm.ShowDialog();
        }

        private void FrmmaterialStockListDetail_Load(object sender, EventArgs e)
        {
            bindingSourcematerialType.DataSource = materialType.getmaterialTypeBymtypeparent("原材料");
            comboBoxMtype.DataSource = bindingSourcematerialType;
            comboBoxMtype.DisplayMember = "mtype";
            comboBoxMtype.ValueMember = "mtype";
            bindingSourcesupplierList.DataSource = supplier.GetDatasupplierListBysTypeNo();
            comboBoxsNum.DataSource = bindingSourcesupplierList;
            comboBoxsNum.DisplayMember = "sName";
            comboBoxsNum.ValueMember = "sNum";
            comboBoxMtype.Text = "";
            comboBoxsNum.Text = "";
            //bindingSourcematerialStockList.DataSource = basicSql.getmaterialListstockDetailALL(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "%" + textmatName.Text + "%", "%" + comboBoxMatSpec.Text + "%", "%" + comboBoxsNum.Text + "%", "%" + comboBoxMtype.Text + "%");
            //dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
            //DcolumnSet.colSet(moduleInfo.materialListstockDetail, dGridmaterialStockList);
            //toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
        }

        private void dGridmaterialStockList_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void buttonQuery_Click(object sender, EventArgs e)
        {
            bindingSourcematerialStockList.DataSource = basicSql.getmaterialListstockDetail(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "%" + textmatName.Text + "%", "%" +comboBoxMatSpec.Text + "%", "%" + comboBoxsNum.Text + "%", "%" + comboBoxMtype.Text + "%");
            dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
            DcolumnSet.colSet(moduleInfo.materialListstockDetail, dGridmaterialStockList);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bindingSourcematerialStockList.DataSource = basicSql.getmaterialListstockDetailALL(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "%" + textmatName.Text + "%", "%" + comboBoxMatSpec.Text + "%", "%" + comboBoxsNum.Text + "%", "%" + comboBoxMtype.Text + "%");
            dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
            DcolumnSet.colSet(moduleInfo.materialListstockDetail, dGridmaterialStockList);
            toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否结算"+dateTimePicker1.Value.ToShortDateString()+"至"+dateTimePicker2.Value.ToShortDateString()+"原材料单据", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    basicSql.cgthckMasterUpdate(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(),"结算");
                    basicSql.cgshrkMasterUpdate (dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "结算");
                    basicSql.rlckMasterUpdate (dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "结算");
                    basicSql.rltkMasterUpdate (dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "结算");
                    MessageBox.Show("结算成功");
                }
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult result = MessageBox.Show("是否反结算" + dateTimePicker1.Value.ToShortDateString() + "至" + dateTimePicker2.Value.ToShortDateString() + "原材料单据", "提示信息", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    basicSql.cgthckMasterUpdate(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "反结算");
                    basicSql.cgshrkMasterUpdate(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "反结算");
                    basicSql.rlckMasterUpdate(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "反结算");
                    basicSql.rltkMasterUpdate(dateTimePicker1.Value.ToShortDateString(), dateTimePicker2.Value.ToShortDateString(), "反结算");
                    MessageBox.Show("反结算成功");
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }




    }
}
